#include "StdAfx.h"


CCharListWnd::CCharListWnd(void)
{
	m_pState=NULL;
	m_pList=NULL;
}

CCharListWnd::CCharListWnd(CD3DGUI * pGUI)
	:CD3DWnd(pGUI)
{
	m_pState=NULL;
	m_pList=NULL;
}

CCharListWnd::~CCharListWnd(void)
{
}

BOOL CCharListWnd::OnMessage(CD3DWnd * pWnd,UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{	
	case WM_D3DGUI_CHILD_LOADED:
		m_pList=dynamic_cast<CD3DSimpleList *>(GetChildWndByName("CharList"));
		return true;
	case WM_D3DGUI_BUTTON_CLICK:
		{
			switch(wParam)
			{
			case 1001:
				m_pState->StartCreateChar();
				return true;
			case 1002:
				return true;
			}
		}
		break;
	case WM_D3DGUI_SIMPLE_LIST_SELCHANGE:
		if(m_pList)
		{
			UINT Index=(UINT)m_pList->GetItemData(lParam);
			m_pState->ShowChar(Index);
		}
		return true;
	case WM_D3DGUI_SIMPLE_LIST_LDBCLICK:
		return true;
	}
	return CD3DWnd::OnMessage(pWnd,msg,wParam,lParam);
}

void CCharListWnd::FillList(CEasyArray<CBaseCharInfo *>& CharInfoList)
{
	if(m_pList)
	{
		m_pList->DeleteAllItem();
		for(UINT i=0;i<CharInfoList.GetCount();i++)
		{
			int Item=m_pList->AddItem(CharInfoList[i]->GetCharName());
			m_pList->SetItemData(Item,(void *)i);
		}
	}
	
}

int CCharListWnd::GetSelectedChar()
{
	if(m_pList)
	{
		int Item=m_pList->GetFirstSelectedItem();
		if(Item>=0)
		{
			return (int)m_pList->GetItemData(Item);
		}
		return -1;
	}
	return -1;
}